import { NextFunction, Request, Response } from "express";
import createError from "http-errors";
import errorHandler from "./middlewares/errorHandler";
// import verificationToken from "./middlewares/verificationToken";

import payModuleList from "./pay/index";
import weChatyModuleList from "./weChaty/index"
const apiList: any[][] = [payModuleList, weChatyModuleList];

export function createRouter(app: any) {
  // 验证token
  // app.use("/", verificationToken);

  // 注册各模块
  for (const module of apiList) {
    for (const item of module) {
      app.use(item.url, item.router);
    }
  }

  // 404
  app.use((_req: Request, _res: Response, next: NextFunction) => {
    next(createError(404));
  });

  // 错误处理
  app.use(errorHandler);
}
